package com.adminx.web.controller;

import com.adminx.po.Category;
import com.adminx.service.CategoryService;
import com.adminx.service.impl.CategoryServiceImpl;
import com.adminx.utils.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/adminx/category")
public class CategoryController extends CommonController {

    private CategoryService categoryService = new CategoryServiceImpl() ;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        findCategoryList(req, resp);
    }

    private void findCategoryList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // process the req
        List<Category> categoryList = categoryService.findCategoryList() ;
        ModelAndView retModel = ModelAndView.buildSuccess(resp) ;
        retModel.addAttribute("categoryList", categoryList) ;
        retModel.response();
    }



}
